package com.cloudsigns.factorymanager2.project.activity;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.project.fragment.PersonnelControlPermissionFragment;
import com.cloudsigns.factorymanager2.project.fragment.PersonnelManagementPermissionFragment;

public class PersonnelSettingPermissionActivity extends FragmentActivity implements View.OnClickListener {
    private String TAG = PersonnelSettingPermissionActivity.class.getSimpleName();
    private ImageView img_back;
    private TextView tv_title;
    private TextView tv_management_permission, tv_control_permission;
    private boolean boo1, boo2;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }

        setContentView(R.layout.layout_personnel_setting_permission);

        init();
    }

    private void init() {
        img_back = findViewById(R.id.img_back);
        tv_title = findViewById(R.id.tv_title);
        tv_management_permission = findViewById(R.id.tv_management_permission);
        tv_control_permission = findViewById(R.id.tv_control_permission);

        tv_title.setText("设置权限");
        img_back.setOnClickListener(this);
        tv_management_permission.setOnClickListener(this);
        tv_control_permission.setOnClickListener(this);

        getSupportFragmentManager().beginTransaction().replace(R.id.frame_permission, new PersonnelManagementPermissionFragment()).commit();

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            //返回
            case R.id.img_back:
                finish();
                break;
            // 管理权限
            case R.id.tv_management_permission:
                if (boo1) {
                    tv_management_permission.setTextColor(getResources().getColor(R.color.color_1d90d6));
                    tv_management_permission.setBackground(getResources().getDrawable(R.drawable.bg_blue_border));
                    boo1 = !boo1;
                } else {

                    tv_management_permission.setTextColor(getResources().getColor(R.color.rgb_ffffffff));
                    tv_management_permission.setBackground(getResources().getDrawable(R.drawable.bg_blue_rec));

                    tv_control_permission.setTextColor(getResources().getColor(R.color.color_1d90d6));
                    tv_control_permission.setBackground(getResources().getDrawable(R.drawable.bg_blue_border));

                    getSupportFragmentManager().beginTransaction().replace(R.id.frame_permission, new PersonnelManagementPermissionFragment()).commit();
                }
                break;
            // 管控权限
            case R.id.tv_control_permission:
                if (boo2) {
                    tv_control_permission.setTextColor(getResources().getColor(R.color.color_1d90d6));
                    tv_control_permission.setBackground(getResources().getDrawable(R.drawable.bg_blue_border));
                    boo2 = !boo2;
                } else {
                    tv_management_permission.setTextColor(getResources().getColor(R.color.color_1d90d6));
                    tv_management_permission.setBackground(getResources().getDrawable(R.drawable.bg_blue_border));

                    tv_control_permission.setTextColor(getResources().getColor(R.color.rgb_ffffffff));
                    tv_control_permission.setBackground(getResources().getDrawable(R.drawable.bg_blue_rec));

                    getSupportFragmentManager().beginTransaction().replace(R.id.frame_permission, new PersonnelControlPermissionFragment()).commit();
                }
                break;
        }
    }
}
